import socket
import time


client_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client_socket.bind(("",7788))
client_socket.listen(128)
client_socket.setblocking(False)
client_list = list()
while True:
    try:
        new_socket, new_addr = client_socket.accept()
    except Exception as ret:
        print("没有用户到来")
    else:
        print('来了一个用户')
        new_socket.setblocking(False)
        client_list.append(new_socket)

    for i in client_list:
        try:
            data = i.recv(1024).decode('gbk')
        except Exception as ret:
            print('客户端没有发送数据')
        else:
            print("客户端发过来数据了")
            if data != '':
                print(data)
                time.sleep(5)
            else:
                client_list.remove(i)
                print(i,'走了')
        
